//
//  YWTroubleMissionManager.m
//  maintain
//
//  Created by 烟雨云渊 on 17/3/7.
//  Copyright © 2017年 ewin. All rights reserved.
//

#import "YWTroubleMissionManager.h"
#import "MJExtension.h"
#import "WMHttpTool.h"
#import "YWCommonTool.h"
#import "YWMacro.h"
#import "YWConst.h"

#import "YWTroubleMissionDBManager.h"
#import "YWMissionManager.h"
#import "YWEquipmentTroubleRecord.h"
#import "YWTroubleMissionModel.h"
#import "YWResourceManager.h"
#import "YWEquipment.h"
#import "YWEquipmentManager.h"
#import "YWLocation.h"
#import "YWBuildingManager.h"
#import "YWFloor.h"
#import "YWApartment.h"
#import "YWBuilding.h"
#import "YWLogRecordTool.h"
#import "YWLoginTool.h"
#import "YWMissionManager.h"
#import "YWCirculationManager.h"
#import "YWNotifyManager.h"
#import "YWEwinManager.h"
#import "YWEquipmentFieldRecord.h"
#import "YWEquipmentType.h"
#import "YWReportTroubleModel.h"
#import "YWReportTroubleManager.h"
#import <Bugly/Bugly.h>

static BOOL isUploading = NO;

@interface YWTroubleMissionManager()
@property (nonatomic, strong) dispatch_group_t group;
//@property (nonatomic, strong) dispatch_queue_t serialQueue;
//@property (nonatomic, strong) dispatch_semaphore_t signal;
@end

@implementation YWTroubleMissionManager
YWSingletonM(Manager)

- (dispatch_group_t)group{
    if (!_group) {
        _group = dispatch_group_create();
    }
    return _group;
}

//- (dispatch_queue_t)serialQueue{
//    if (!_serialQueue) {
//        _serialQueue = dispatch_queue_create("uploadTroubleMissionSerialQueue", DISPATCH_QUEUE_SERIAL); //创建上传串行队列
//    }
//    return _serialQueue;
//}
//
//- (dispatch_semaphore_t)signal{
//    if (!_signal) {
//        _signal = dispatch_semaphore_create(1);
//    }
//    return _signal;
//}

- (BOOL)updateTroubleMissionWithArray:(NSArray*)troubleMissionArray needUpdateReportTrouble:(BOOL)need{
    return [[YWTroubleMissionDBManager shareManager] updateTroubleMissionWithArray:troubleMissionArray needUpdateReportTrouble:need];
}

- (BOOL)setUploadFailWithTroubleMissionModel:(YWTroubleMissionModel*)troubleMission{
    return [[YWTroubleMissionDBManager shareManager] setUploadFailWithTroubleMissionModel:troubleMission];
}

- (NSArray*)troubleMissionModelWithStatus:(YWTroubleMissionStatus)status page:(NSInteger)page{
    return [[YWTroubleMissionDBManager shareManager] troubleMissionModelWithStatus:status page:page];
}

- (YWTroubleMissionModel*)troubleMissionModelWithTroubleId:(NSInteger)troubleId{
    return [[YWTroubleMissionDBManager shareManager] troubleMissionModelWithTroubleId:troubleId];
}

- (NSArray*)uploadFailTroubleMissionArray{
    return [[YWTroubleMissionDBManager shareManager] uploadFailTroubleMissionArray];
}

- (BOOL)saveTroubleRecordJsons:(NSArray*)troubleRecordJsons
{
    if (!troubleRecordJsons.count) {
        return NO;
    }
    return [[YWDBTool shareDBTool] saveEquipmentTroubleRecordWithJsonArray:troubleRecordJsons];
}

- (BOOL)updateTroubleRecord:(YWEquipmentTroubleRecord*)troubleRecord
{
    if (!troubleRecord) {
        return NO;
    }
    return [[YWDBTool shareDBTool] updateEquipmentTroubleRecordWithArray:@[ troubleRecord ]];
}

- (NSArray*)troubleRecordArrayWithEquipmentId:(NSString*)equipmentId andPage:(NSInteger)page{
    return [[YWDBTool shareDBTool] troubleRecordArrayWithEquipmentId:equipmentId andPage:page];
}

- (YWEquipmentTroubleRecord*)troubleRecordWithMissionId:(NSInteger)missionId
{
    return [[YWDBTool shareDBTool] troubleRecordWithMissionId:missionId];
}

-(BOOL)updateTroubleMissionStatus:(NSInteger)status troubleId:(NSInteger)troubleId{
    return [[YWTroubleMissionDBManager shareManager]updateTroubleMissionStatus:status troubleId:troubleId];
}

- (void)requestTroubleRecordWithEquipmentIds:(NSString *)equipmentIds page:(NSInteger)page pageSize:(NSInteger)pageSize completeBlock:(void (^)(NSInteger))complete{
    NSDictionary *headersDic = [YWCommonTool addSubHttpHeadWithDic:[WMHttpTool shareHttpTool].HTTPHeaders];
    [WMHttpTool shareHttpTool].HTTPHeaders = headersDic;
    if (headersDic == nil) {if (complete) {complete(0);}return;}
    
    NSMutableDictionary* params = [NSMutableDictionary dictionary];
    [params setObject:equipmentIds forKey:@"equipmentId"];
    if (page) {
        [params setObject:@(page) forKey:@"page"];
    }
    if (pageSize) {
        [params setObject:@(pageSize) forKey:@"pageSize"];
    }
    [[WMHttpTool shareHttpTool] getWithUrl:[YWCommonTool getTroubleRecordUrl] params:params success:^(NSHTTPURLResponse* response, id json) {
        NSArray* troubleRecordJsons = [YWEquipmentTroubleRecordJson mj_objectArrayWithKeyValuesArray:json];
        if (troubleRecordJsons.count) {
            [self saveTroubleRecordJsons:troubleRecordJsons];
        }
        if (complete) {
            complete(troubleRecordJsons.count);
        }
    } failure:^(NSHTTPURLResponse* response, NSError* error) {
       if (complete) {
           complete(0);
       }
       if (![[WMHttpTool shareHttpTool] existenceNetwork]) {
           [YWCommonTool showTextHUDWithContent:NSLocalizedString(kTextNoNetwork, nil)];
       }
       YWLog(@"%s,error:%@", __func__, error.localizedDescription);
    }];
}

- (void)requestTroubleMissionWithPage:(NSInteger)page pageSize:(NSInteger)pageSize troubleStatus:(NSInteger)troubleStatus completeBlock:(void (^)(NSInteger))complete{
    //请求维修任务
    NSDictionary *headersDic = [YWCommonTool addSubHttpHeadWithDic:[WMHttpTool shareHttpTool].HTTPHeaders];
    [WMHttpTool shareHttpTool].HTTPHeaders = headersDic;
    if (headersDic == nil) {if (complete) {complete(0);}return;}
    
    NSString *url = [YWCommonTool getTroubleMissionUrl];
    NSMutableDictionary* params = [NSMutableDictionary dictionary];
    [params setValue:[@(troubleStatus) stringValue] forKey:@"troubleStatus"];
    if (page) {
        [params setValue:@(page) forKey:@"page"];
    }
    if (pageSize) {
        [params setValue:@(pageSize) forKey:@"pageSize"];
    }
    NSInteger uniqueId = [YWLoginTool loginUser].uniqueId;
    [params setValue:@(uniqueId) forKey:@"executorId"];
    //    if (pullTime) {
    //        [params setValue:@(pullTime) forKey:@"pullTime"];
    //    }
    YWLog(@"params:%@",params);
    [[WMHttpTool shareHttpTool] getWithUrl:url params:params success:^(NSHTTPURLResponse* response, id json) {
        NSArray* troubleMissionJsons = [YWTroubleMissionModelApiJson mj_objectArrayWithKeyValuesArray:json];
        //        [[YWMissionManager shareManager] saveMissionWithTroubleMissionJsonArray:troubleMissionJsons];
        [[YWTroubleMissionManager shareManager] updateTroubleMissionWithArray:troubleMissionJsons needUpdateReportTrouble:YES];
        if (complete) {
            complete(troubleMissionJsons.count);
        }
    } failure:^(NSHTTPURLResponse* response, NSError* error) {
        if (complete) {
            complete(0);
        }
        if (![[WMHttpTool shareHttpTool] existenceNetwork]) {
            [YWCommonTool showTextHUDWithContent:NSLocalizedString(kTextNoNetwork, nil)];
        }
        YWLog(@"%s,error:%@", __func__, error.localizedDescription);
    }];
}

#pragma mark --- 上传维修记录

- (void)startUploadTroubleMissionRecords:(NSArray*)records troubleMissionModel:(YWTroubleMissionModel*)mission pictures:(NSArray*)pictures{
    if (records.count ==0 || mission == nil) {
        return;
    }
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        dispatch_group_enter(self.group);
        if (pictures.count>0) {
            [[YWResourceManager shareManager]
             uploadLocalPictureToAliyunOSS:pictures isAvatar:NO complete:^(BOOL isError, NSArray* uploadPictures) {
                 [self missionCompleteHandleWithTroubleMissionRecords:records troubleMissionModel:mission uploadPictures:uploadPictures error:isError];
             }];
        }else{
            [self missionCompleteHandleWithTroubleMissionRecords:records troubleMissionModel:mission uploadPictures:nil error:NO];
        }
        dispatch_group_wait(self.group, DISPATCH_TIME_FOREVER);
    });
}

- (void)missionCompleteHandleWithTroubleMissionRecords:(NSArray*)records troubleMissionModel:(YWTroubleMissionModel*)troubleMissionModel uploadPictures:(NSArray*)uploadPictures error:(BOOL)isError{
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        [[YWResourceManager shareManager] savePicturesToDBWithArray:uploadPictures];
        if (!isError) {
            [self submitTroubleMissionRequestWithMission:troubleMissionModel Record:records.count ? records[0] : nil Pictures:uploadPictures];
        }else{
            //更新上传状态
            YWEquipmentTroubleRecord *troubleRecord = records.count ? records[0] : nil;
            [[YWMissionManager shareManager] updateMissionMaintenceRecordUploadStatus:YWEquipmentMaintenanceRecordUploadStatusUnFinished recordId:troubleRecord.recordId maintenanceTypeId:YWMaintenanceTypeTrouble];
            
            troubleMissionModel.uploadFail = YES;
            [self setUploadFailWithTroubleMissionModel:troubleMissionModel];
            dispatch_group_leave(self.group);
        }
    });
}

- (void)submitTroubleMissionRequestWithMission:(YWTroubleMissionModel*)troubleMission Record:(YWEquipmentTroubleRecord*)troubleRecord Pictures:(NSArray*)pictures{
    if (!troubleMission || !troubleRecord) {
        dispatch_group_leave(self.group);
        return;
    }
    NSDictionary *headers = [YWCommonTool addSubHttpHeadWithDic:[WMHttpTool shareHttpTool].HTTPHeaders];
    [WMHttpTool shareHttpTool].HTTPHeaders = headers;
    if (headers == nil) {dispatch_group_leave(self.group);return;}
    
    NSMutableDictionary* params = [NSMutableDictionary dictionary];
    if (troubleMission.trouble.troubleId > 0) {
        [params setValue:@(troubleMission.trouble.troubleId) forKey:@"trouble.troubleId"];
    }
    [params setValue:@(troubleMission.trouble.location.locationId) forKey:@"location.locationId"];
    
    [params setValue:troubleRecord.equipmentId ?: @"" forKey:@"equipment.equipmentId"];
    [params setValue:troubleRecord.note ?: @"" forKey:@"note"];
    [params setValue:@(troubleRecord.recordType) forKey:@"recordType"];
    [params setValue:@(troubleRecord.reasonId) forKey:@"reasonId"];
    if (troubleRecord.laborCosts.length>0) {
        [params setValue:troubleRecord.laborCosts ?: @"" forKey:@"laborCosts"];
    }
    if (troubleRecord.materialCosts.length>0) {
        [params setValue:troubleRecord.materialCosts ?: @"" forKey:@"materialCosts"];
    }
    //临时任务增加uniqueTag
    NSString *uniqueTag = troubleRecord.uniqueTag?:[YWCommonTool randStringId];
    [params setValue:uniqueTag forKey:@"uniqueTag"];
    //配件
    [params setValue:@(troubleRecord.replacementStatus) forKey:@"replacementStatus"];
    if (troubleRecord.replacements.count==0) {
        troubleRecord.replacements = [troubleRecord.replacementName componentsSeparatedByString:@","];
    }
    [troubleRecord.replacements enumerateObjectsUsingBlock:^(NSString*  _Nonnull replacementName, NSUInteger idx, BOOL * _Nonnull stop) {
        [params setValue:replacementName forKey:[NSString stringWithFormat:@"replacements[%lu].replacementName", (unsigned long)idx]];
    }];
    //图片
    [pictures enumerateObjectsUsingBlock:^(YWPicture* _Nonnull picture, NSUInteger idx, BOOL* _Nonnull stop) {
        [params setValue:picture.bigPictureUrl ?: @"" forKey:[NSString stringWithFormat:@"pictures[%lu].url", (unsigned long)idx]];
        [params setValue:picture.smallPictureUrl ?: @"" forKey:[NSString stringWithFormat:@"pictures[%lu].thumbnailUrl", (unsigned long)idx]];
        [params setValue:picture.smallPictureUrl ?: @"" forKey:[NSString stringWithFormat:@"pictures[%lu].previewUrl", (unsigned long)idx]];
    }];
    //自定义属性
    [troubleRecord.equipmentFieldRecord enumerateObjectsUsingBlock:^(YWEquipmentFieldRecord*  _Nonnull fieldRecord, NSUInteger cusIdx, BOOL * _Nonnull stop) {
        if (fieldRecord.fieldTypeId == YWEquipmentFieldTypeIdDownSelect) {
            [params setValue:@(fieldRecord.fieldId) forKey:[NSString stringWithFormat:@"equipmentFields[%lu].fieldId", (unsigned long)cusIdx]];
            [params setValue:@(fieldRecord.fieldOption.fieldOptionId) forKey:[NSString stringWithFormat:@"equipmentFields[%lu].fieldValue", (unsigned long)cusIdx]];
        }else{
            if (fieldRecord.fieldValue.length>0) {
                [params setValue:@(fieldRecord.fieldId) forKey:[NSString stringWithFormat:@"equipmentFields[%lu].fieldId", (unsigned long)cusIdx]];
                [params setValue:fieldRecord.fieldValue ?: @"" forKey:[NSString stringWithFormat:@"equipmentFields[%lu].fieldValue", (unsigned long)cusIdx]];
            }
        }
    }];
    
    long long executeTime = [YWCommonTool numberWithTime:troubleRecord.completeTime];
    [params setValue:@(executeTime) forKey:@"clientExecuteTime"];
    long long nowTime = [YWCommonTool numberWithTime:[[NSDate date] timeIntervalSince1970]*1000];
    [params setValue:@(nowTime) forKey:@"clientCurrentTime"];
    long long scanTime = [YWCommonTool numberWithTime:troubleRecord.clientScanTime];
    scanTime = scanTime<0?0:scanTime;
    [params setValue:@(scanTime) forKey:@"clientScanTime"];
    NSString *url = [YWCommonTool getSubmitTroubleMissionUrl];
    YWLog(@"url -- %@,%@",url,params);
    //保存请求前的参数日志
    NSString *logTag = [YWCommonTool randStringId];
    NSMutableDictionary * logDic = [[YWLogRecordTool shareLogRecordManager] getLogDictionaryWithModule:@"维修" interface:url params:params headers:headers tag:logTag];
    [[YWLogRecordTool shareLogRecordManager] saveLocalPatameterLog:logDic];
    
    [[WMHttpTool shareHttpTool] postWithUrl:url params:params success:^(NSHTTPURLResponse* response, id json) {
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            YWLog(@"trouble mission upload success");
            //API只返回recordId
//                YWEquipmentTroubleRecord* jsonRecord = [YWEquipmentTroubleRecord mj_objectWithKeyValues:json];
    
            [[YWMissionManager shareManager] updateMissionMaintenceRecordUploadStatus:YWEquipmentMaintenanceRecordUploadStatusFinished recordId:troubleRecord.recordId maintenanceTypeId:YWMaintenanceTypeTrouble];
            [[YWEwinManager shareManager] subtractTotalCountWithType:YWUnReadCountTypeFixTrouble];
            
            if (troubleMission.uploadFail) {
                NSArray* unUploadRecord = [[YWDBTool shareDBTool] finishedUnUploadTroubleRecord:troubleMission.trouble.troubleId];
                if (unUploadRecord.count == 0) {
                    troubleMission.uploadFail = NO;
                    [self setUploadFailWithTroubleMissionModel:troubleMission];
                }
            }
            //保存请求成功的参数日志
            NSMutableDictionary * successDic =
            [[YWLogRecordTool shareLogRecordManager] successOrFailedLogDicWith:logDic statusCode:response.statusCode errorInfo:@"无" logTag:logTag];
            [[YWLogRecordTool shareLogRecordManager] saveLocalPatameterLog:successDic];
            
            dispatch_group_leave(self.group);
        });
    } failure:^(NSHTTPURLResponse* response, NSError* error) {
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            YWLog(@"%s,error:%@", __func__, error.localizedDescription);
            //保存请求失败的参数日志
            NSString * result = [NSString stringWithFormat:@"%s,error:%@", __func__, error.localizedDescription];
            NSMutableDictionary * failedDic = [[YWLogRecordTool shareLogRecordManager] successOrFailedLogDicWith:logDic statusCode:response.statusCode errorInfo:result logTag:logTag];
            [[YWLogRecordTool shareLogRecordManager] saveLocalPatameterLog:failedDic];
            
            //上传错误参数
            if ([[WMHttpTool shareHttpTool] existenceNetwork]) {
                NSString *statusCode = [NSString stringWithFormat:@"statusCode: %@",@(response.statusCode).stringValue];
                [Bugly reportException:[NSException exceptionWithName:@"维修接口错误" reason:statusCode userInfo:params]];
            }
            
            //更新上传状态
            [[YWMissionManager shareManager] updateMissionMaintenceRecordUploadStatus:YWEquipmentMaintenanceRecordUploadStatusUnFinished recordId:troubleRecord.recordId maintenanceTypeId:YWMaintenanceTypeTrouble];
            
            troubleMission.uploadFail = YES;
            [self setUploadFailWithTroubleMissionModel:troubleMission];
            dispatch_group_leave(self.group);
        });
    }];
}

- (void)startUnUploadTroubleMissionRecord{
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        if (![YWLoginTool isLogin]) {
            return;
        }
        if (isUploading == YES) {
            return;
        }
        isUploading = YES;
        
        NSArray* uploadFailMissions = [self uploadFailTroubleMissionArray];
        [uploadFailMissions enumerateObjectsUsingBlock:^(YWTroubleMissionModel* _Nonnull mission, NSUInteger idx, BOOL* _Nonnull stop) {
            //记录
            NSArray* uploadRecords = [[YWDBTool shareDBTool] finishedUnUploadTroubleRecord:mission.trouble.troubleId];
            //图片
            NSArray* pictures = [[YWDBTool shareDBTool] picturesWithTroubleMissionId:mission.trouble.troubleId pictureTroubleType:YWPictureTroubleTypeRecord];
            
            if (uploadRecords.count > 0 && mission) {
                dispatch_group_enter(self.group);
                if (pictures.count>0) {
                    [[YWResourceManager shareManager]
                     uploadLocalPictureToAliyunOSS:pictures isAvatar:NO complete:^(BOOL isError, NSArray* uploadPictures) {
                         [self missionCompleteHandleWithTroubleMissionRecords:uploadRecords troubleMissionModel:mission uploadPictures:uploadPictures error:isError];
                     }];
                }else{
                    [self missionCompleteHandleWithTroubleMissionRecords:uploadRecords troubleMissionModel:mission uploadPictures:nil error:NO];
                }
                dispatch_group_wait(self.group, DISPATCH_TIME_FOREVER);
            }
            
            if (idx == uploadFailMissions.count-1) {
                dispatch_async(dispatch_get_main_queue(), ^{
                    [[NSNotificationCenter defaultCenter] postNotificationName:KPushBackgroundUploadRecordSuccessNotification object:nil];
                });
            }
        }];
        isUploading = NO;
    });
}

- (void)updateTroubleMissionModelStatus{
    /**
     *  更新维修任务状态
     */
    NSString* troubleIdString = [[YWTroubleMissionDBManager shareManager] allUnfinishTroubleMissionIds];
    
    // YWLog(@"%@", missionString);
    if (troubleIdString.length) {
        NSDictionary *headersDic = [YWCommonTool addSubHttpHeadWithDic:[WMHttpTool shareHttpTool].HTTPHeaders];
        [WMHttpTool shareHttpTool].HTTPHeaders = headersDic;
        if (headersDic == nil) {return;}
        [[WMHttpTool shareHttpTool] getWithUrl:[YWCommonTool getTroubleSituationUrl] params:@{ @"troubleIds" : troubleIdString ?: @"" } success:^(NSHTTPURLResponse* response, id json) {
            NSArray* troubleSituationJsons = [YWReportTroubleModel mj_objectArrayWithKeyValuesArray:json];
            YWLoginUser *currentUser = [YWLoginTool loginUser];
            [troubleSituationJsons enumerateObjectsUsingBlock:^(YWReportTroubleModel*  _Nonnull troubleJson, NSUInteger idx, BOOL * _Nonnull stop) {
                //判断这个任务执行人有没有被更改
                //                if (![YWLoginTool loginUser].isTroubleServer && troubleJson.executor.uniqueId != currentUser.uniqueId && troubleJson.creator.uniqueId != currentUser.uniqueId && troubleJson.reporter.uniqueId != currentUser.uniqueId && ![troubleJson.observerIds containsString:@(currentUser.uniqueId).stringValue]) {
                if (![YWLoginTool loginUser].isTroubleServer && troubleJson.troubleMission.executor.uniqueId != currentUser.uniqueId && troubleJson.troubleMission.creator.uniqueId != currentUser.uniqueId && troubleJson.reporter.uniqueId != currentUser.uniqueId && ![troubleJson.observerIds containsString:@(currentUser.uniqueId).stringValue]) {
                    //修改任务为取消报障状态
                    [[YWMissionManager shareManager] mofifyMissionStatusWithMissionId:troubleJson.troubleId maintenanceType:YWMaintenanceTypeTrouble];
                    //修改报障单状态为取消报障
                    [[YWReportTroubleManager shareManager] updateReportTroubleStatus:YWTroubleMissionStatusCancelPostTrouble troubleId:troubleJson.troubleId];
                }else{
                    //更新
                    if (troubleJson.troubleStatus== YWTroubleMissionStatusFinish) {
                        [[YWReportTroubleManager shareManager] updateReportTroubleWithArray:@[troubleJson]];
                    }
                    //                    if (troubleJson.troubleStatus== YWTroubleMissionStatusFinish) {
                    //该方法不使用，接口未定
                    //                        [[YWMissionManager shareManager] saveMissionWithTroubleMissionJsonArray:@[troubleJson]];
                    //                    }
                }
            }];
            
        } failure:^(NSHTTPURLResponse* response, NSError* error) {
            YWLog(@"%s,error:%@", __func__, error.localizedDescription);
        }];
    }
}

- (void)requestTroubleMissionStatus:(NSString*)troubleIdString withComplete:(void (^)(bool success))complete{
    if (troubleIdString.length<=0) {
        return;
    }
    NSDictionary *headersDic = [YWCommonTool addSubHttpHeadWithDic:[WMHttpTool shareHttpTool].HTTPHeaders];
    [WMHttpTool shareHttpTool].HTTPHeaders = headersDic;
    if (headersDic == nil) {if (complete) {complete(NO);}return;}
    
    [[WMHttpTool shareHttpTool] getWithUrl:[YWCommonTool getTroubleSituationUrl] params:@{ @"troubleIds" : troubleIdString ?: @"" } success:^(NSHTTPURLResponse* response, id json) {
        NSArray* troubleSituationJsons = [YWReportTroubleModel mj_objectArrayWithKeyValuesArray:json];
        if (troubleSituationJsons.count) {
            //不再使用YWTroubleMissionModelJson模型，接口未定
            //            [[YWMissionManager shareManager] saveMissionWithTroubleMissionJsonArray:troubleSituationJsons];
            [[YWReportTroubleManager shareManager] updateReportTroubleWithArray:troubleSituationJsons];
        }
        if (complete) {
            complete(YES);
        }
    } failure:^(NSHTTPURLResponse* response, NSError* error) {
        YWLog(@"%s,error:%@", __func__, error.localizedDescription);
        if (complete) {
            complete(NO);
        }
    }];
}


@end
